<?php

echo $breadcrumb;
?>
<div id="content">
    <div id="content2">
        <div class="DivTable">
            <table class="GridTable">
                <tr>
                    <td colspan="21" class="noborder"><div class="box-control"></div></td>
                </tr>
                <tr class="GridHeader">
                    <td width="20">No.</td>
                    <td width="300">Title</td>
                    <td>Aktif</td>
                    <td>Tidak Aktif</td>
                    <td>Jumlah Total Pengguna</td>
                </tr>
                <tr class="GridItem1">
                    <td width="20">1</td>
                    <td>Resume Data Pengguna</td>
                    <td style="text-align:center"><?php echo $this->user_model->get_scalar("SELECT COUNT(id_user) AS total FROM mt_user WHERE is_active = 1", "total") ?></td>
                    <td style="text-align:center"><?php echo $this->user_model->get_scalar("SELECT COUNT(id_user) AS total FROM mt_user WHERE is_active = 0", "total") ?></td>
                    <td style="text-align:center"><?php echo $this->user_model->get_scalar("SELECT COUNT(id_user) AS total FROM mt_user", "total") ?></td>
                </tr>
            </table>
        </div>
        <br class="bersih" />
    </div>
    <div class="DivTable">
        <form name="fCari" id="fCari" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" >
            <table class="GridTableFilter">
                <?php
                echo $fp;
                ?>
                <tr>
                    <td>
                        <?php
                        echo $fp2;
                        ?>
                    </td>
                </tr>
            </table>
        </form>

        <script language="javascript">
            function removeData(kode) {

                if(confirm('Anda yakin akan menghapus data ini?')) {
                    location.href = '<?php echo base_url() ?>index.php/management/user_bm_delete/' + kode;
                }
            }

            function setIsActive(kode, flag) {
                if(confirm('Anda yakin akan mengubah status id '+ kode +' ini ?')) {
                    location.href = '<?php echo base_url() ?>index.php/management/user_bm_setAktif/' + kode + '/'+ flag;
                }
            }

            function detil(kode){
                return GB_showCenter('Data Log Pengguna', '<?php echo base_url() ?>index.php/popup/log_user/'+ kode, 500, 850);
            }

            function exportData(){
                location.href = '<?php echo base_url() ?>index.php/management/user_bm_export/?<?php echo $_SERVER["QUERY_STRING"] ?>';
            }
        </script>

        <table class="GridTable" style="width:100%">
            <tr>
                <td colspan="20" class="noborder">
                    <div class="box-control">
                        <?php
                        echo Greybox::createLink(base_url() . "index.php/management/user_bm_add", "", "Tambah Data", "add");
                        echo Greybox::createLink(base_url() . "index.php/management/user_bm_export/", "", "Export Data", "report");
                        echo "<a href=\"#\" class=\"search\" title=\"Cari Data\">&nbsp;</a>";
                        echo "<a href=\"" . base_url() . "index.php/management/user\" class=\"refresh\" title=\"Muat Ulang\">&nbsp;</a>";
                        ?>
                    </div>
                </td>
            </tr>

            <tr class="GridHeader">
                <td width="20">No.</td>
                <td>&nbsp;</td>
                <td>ID Pengguna</td>
                <td>NIK</td>
                <td>Nama Rekan</td>
                <td>No.HP</td>
                <td>Email</td>
                <td>Kelompok Pengguna</td>
                <!--<td>Jumlah Aktifitas Hari Ini</td>-->
                <td>Login terakhir</td>
                <td>St.Aktif</td>

            </tr>

            <?php
            if ($numRows > 0) {
                $nomor = $post['offset'];
                foreach ($result as $row) {
                    $nomor++;
                    $kodecontent = $row->id_user;
                    $styleTR = "GridItem1";
                    ?>
                    <tr class="<?php echo $styleTR; ?>" >
                        <td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo $nomor; ?></td>
                        <td>
                            <?php
                                echo Greybox::createLink(base_url() . "index.php/management/user_bm_edit/" . $kodecontent . "", "", "Ubah Data", "edit");
                                echo Greybox::createLink(base_url() . "index.php/management/user_bm_hak_akses/" . $kodecontent . "", "", "Setting Hak Akses", "priv");
                                echo "<a href=\"#\" class=\"delete\" title=\"Hapus Data\" onclick=\"javascript:removeData('" . $kodecontent . "')\">&nbsp;</a>";
                                
                            ?>
                            </td>
                        <td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo $row->id_user; ?></td>
                        <td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo $row->nik; ?></td>
                        <td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo $row->nama; ?></td>
                        <td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo $row->no_hp; ?></td>
                        <td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo $row->email; ?></td>
                        <td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo $row->group_user; ?></td>
                        <td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo $row->last_active; ?></td>
                        <td>
                            <?php
                            if ($row->is_active) {
                                echo "<a href=\"#\" class=\"setaktif\" title=\"Set Non Aktif\" onclick=\"javascript:setIsActive('" . $kodecontent . "', '" . $row->is_active . "')\">&nbsp;</a>";
                            } else {
                                echo "<a href=\"#\" class=\"setnonaktif\" title=\"Set Aktif\" onclick=\"javascript:setIsActive('" . $kodecontent . "', '" . $row->is_active . "')\">&nbsp;</a>";
                            }
                            ?>
                        </td>

                    </tr>	
                    <?php
                }
            } else {
                ?>
                <tr class="GridItem1">
                    <td colspan="20">Tidak ada data</td>
                </tr>	

                <?php
            }
            ?>
        </table>
    </div>
    <?php
    echo $paging['pagingView'];
    ?>
    <br class="bersih" />

</div>

<script type="text/javascript">

    function openURL(url) {
        open(''+ url +'', 'wndStaff', 'width=730,height=500,directories=0,location=0,resizable=1,scrollbars=1,toolbar=0,copyhistory=0,status=0');
        return false;
    }

    jQuery(document).ready(function(){
        jQuery(".tr_slide").hide();

        jQuery('.search').click(
        function(){
            jQuery(".tr_slide").slideToggle();
        }
    );

    });
    
    function reset_password(kode)
    {
        if(confirm("Apakah anda yakin ingin mereset password " + kode + "?"))
        {
            return GB_showCenter('Reset Password Pengguna', "<?php echo base_url() ?>index.php/management/user_password_reset/"+ kode, 500, 850);
        }
    }
</script>
